home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12668 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  52 lines

  1. Path: mayne.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Hashing to a file...
  5. Date: 1 Apr 1996 19:26:01 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4jq6o9INNaok@mayne.ugrad.cs.ubc.ca>
  8. References: <Pine.SOL.3.90.960401132142.3433A-100000@kclosure>
  9. NNTP-Posting-Host: mayne.ugrad.cs.ubc.ca
  10.  
  11. In article <Pine.SOL.3.90.960401132142.3433A-100000@kclosure>,
  12. Khan Riaz Ahmad  <a228khao@cdf.toronto.edu> wrote:
  13. >
  14. >    I have been looking for c code for hashing to a file... All the 
  15. >code that I have found so far only show hashing to an array in memory... 
  16. >Anyone know of any good sources for file based hashing???? The main 
  17. >problem I seem to be having is how do we implement the hashing table on 
  18. >the disk... 
  19. >
  20. >
  21. >Any help would be greatly appreciated...
  22. >
  23. >Riaz.
  24.  
  25.  
  26. #define hash(STR)    (crypt(C[1],C)[0] + crypt(C[2],C)[1] << 8)
  27.  
  28.  
  29. #include <unistd.h>
  30. #include <stdio.h>
  31.  
  32. void main(void)
  33.  
  34. {
  35.     int x = hash("joe");
  36.     char buffer[5];
  37.  
  38.     FILE *f = fopen("myfile","r");
  39.  
  40.     while(1) {
  41.         if (!fgets(buffer,5,f))
  42.             break;
  43.  
  44.         if (!stcmp(atoi(buffer),x)) {    
  45.             puts("found it!");
  46.             break;
  47.         } 
  48.     }
  49. }
  50. -- 
  51.  
  52.